<template>
    <view class="orderApprovalDetails">
        <uni-nav-bar fixed left-icon="left" :title="title" @clickLeft="backHandle" class="unibarS">
            <block slot="right">
                <text class="sub-btn" @click="addRefund">新建回款</text>
            </block>
        </uni-nav-bar>
        <!-- 主要内容 -->
        <view class="orderApprovalDetails-content">
            <!-- 任务信息 -->
            <view class="customer-info">
                <uni-row class="demo-uni-row" style="text-align: center;">
                    <uni-col :span="8">
                        <view class="item">
                            <view>订单编号</view>
                            <view>{{ detailsData.orderNumber }}</view>
                        </view>
                    </uni-col>
                    <uni-col :span="8" v-if="detailsData.orderStatus == '1002'">
                        <view class="item">
                            <view>归属人员</view>
                            <view>{{ detailsData.businessManager }}</view>
                        </view>
                    </uni-col>
                    <uni-col :span="8" v-if="detailsData.orderStatus != '1002'">
                        <view class="item">
                            <view>审批状态</view>
                            <view :style="{ color: getColor(detailsData.orderStatus) }">{{ bus_order_status[detailsData.orderStatus] }}</view>
                        </view>
                    </uni-col>
                    <uni-col :span="8" v-if="detailsData.orderStatus == '1002'">
                        <view class="item">
                            <view>下次跟进</view>
                            <view>---</view>
                        </view>
                    </uni-col>
                    <uni-col :span="8">
                        <view class="item">
                            <view>订单总金额</view>
                            <view>¥ {{ detailsData.orderTotalAmount }}</view>
                        </view>
                    </uni-col>
                    <uni-col :span="8" v-if="detailsData.orderStatus == '1002'">
                        <view class="item">
                            <view>已回款金额</view>
                            <view>¥ {{ detailsData.receivedAmount }}</view>
                        </view>
                    </uni-col>
                    <uni-col :span="8" v-if="detailsData.orderStatus == '1002'">
                        <view class="item">
                            <view>未回款金额</view>
                            <view>¥ {{ detailsData.depositAmount }}</view>
                        </view>
                    </uni-col>
                </uni-row>
                <u-steps v-if="getStatus()" :current="current">
                    <u-steps-item title="提交审批"></u-steps-item>
                    <u-steps-item title="业务审批"></u-steps-item>
                    <u-steps-item title="主管审批"></u-steps-item>
                    <u-steps-item title="审批完成"></u-steps-item>
                </u-steps>
            </view>
            <view class="info-c">
                <view>
                    <view class="item-title">基本信息</view>
                    <view class="item-content">
                        <view class="item-content-row">
                            <view>订单标题</view>
                            <view>{{ detailsData.orderNumber }}</view>
                        </view>
                        <view class="item-content-row">
                            <view>关联商机</view>
                            <view>---</view>
                        </view>
                        <view class="item-content-row">
                            <view>关联客户</view>
                            <view>{{ detailsData.customerName }}</view>
                        </view>
                        <view class="item-content-row">
                            <view>商品记录</view>
                            <view>{{ detailsData.commodityList? detailsData.commodityList.length : 0 }}</view>
                        </view>
                        <view class="item-content-row">
                            <view>订单总额</view>
                            <view>{{ detailsData.orderTotalAmount }}</view>
                        </view>
                        <view class="item-content-row">
                            <view>付款方式</view>
                            <view>{{ bus_pay_status[detailsData.paymentMethod] }}</view>
                        </view>
                        <view class="item-content-row">
                            <view>归属人员</view>
                            <view>{{ detailsData.businessManager }}</view>
                        </view>
                        <view class="item-content-row">
                            <view>备注信息</view>
                            <view>{{ detailsData.remark }}</view>
                        </view>
						<view class="item-content-row">
						    <view>创建时间</view>
						    <view>{{ detailsData.createTime }}</view>
						</view>
                    </view>
                </view>
                <!-- <view>
                    <view class="item-title">审批信息</view>
                    <view class="item-content">
                        <view class="item-content-row">
                            <view>提交人员</view>
                            <view>---</view>
                        </view>
                        <view class="item-content-row">
                            <view>提交时间</view>
                            <view>---</view>
                        </view>
                        <view class="item-content-row">
                            <view>1级审批</view>
                            <view>---</view>
                        </view>
                        <view class="item-content-row">
                            <view>2级审批</view>
                            <view>---</view>
                        </view>
                        <view class="item-content-row">
                            <view>审批状态</view>
                            <view>---</view>
                        </view>
                        <view class="item-content-row">
                            <view>审批时间</view>
                            <view>---</view>
                        </view>
                        <view class="item-content-row">
                            <view>通知他人</view>
                            <view>---</view>
                        </view>
                    </view>
                </view> -->
            </view>
        </view>
        <!-- 底部 -->
        <view class="bottom-box"  v-if="getStatus() || detailsData.orderStatus == '1002'">
            <template v-if="getStatus()">
                <view @click="adoptHandle()" class="column-box">
                    <u-icon name="checkbox-mark" color="#00BAAD" size="22"></u-icon>
                    <text style="color: rgba(0, 186, 173, 1);">审批通过</text>
                </view>
                <view @click="vetoHandle()" class="column-box">
                    <u-icon name="close" color="#FF001C" size="22"></u-icon>
                    <text style="color: rgba(255, 0, 28, 1);">审批否决</text>
                </view>
                <view @click="editHandle()" class="column-box">
                    <u-icon name="edit-pen-fill" color="#0C1019" size="22"></u-icon>
                    <text>编辑订单</text>
                </view>
            </template>
            <view  @click="vetoHandle()" v-if="detailsData.orderStatus == '1002'" class="column-box">
                <u-icon name="photo" color="#0C1019" size="22"></u-icon>
                <text>驳回审批</text>
            </view>
        </view>
    </view>
</template>

<script>
import { convertToDict } from '@/common/utils'
export default {

    data() {
        return {
            title: '',
            detailsData: {},
            show: false,
            current: 0
        }
    },
    onLoad(options) {

        this.bus_pay_status = convertToDict(JSON.parse(uni.getStorageSync('bus_pay_status')))
        this.bus_order_status = convertToDict(JSON.parse(uni.getStorageSync('bus_order_status')))
        if(options.id) {
            this.id = options.id
            // this.getDetails()
        }
    },
    onShow: function () {
        this.getDetails()
	},
    methods: {
        getDetails() {
			this.$http.get('/app/order/' + this.id, {}).then(res => {
				if (res.code == 200) {
                    this.title = res.data.customerName
                    // res.data.orderStatus = '1006'
                    this.detailsData = res.data
                    if(res.data.orderStatus == '1003') {
                        this.current = 1
                    } else if (res.data.orderStatus == '1004') {
                        this.current = 2
                    } else if (res.data.orderStatus == '1005') {
                        this.current = 3
                    }
				} else {
					uni.$u.toast(res.msg)
				}
			})
		},
        // 审批通过
        adoptHandle() {
            let that = this
            uni.navigateTo({
                url: '/pages/approval/adop?orderNumber=' + this.detailsData.orderNumber,
                success: function (res) {
                    let processName = '订单审批'
                    res.eventChannel.emit('emitDataHandle', { data: processName })
                }
            });
        },
        // 审批否决
        vetoHandle() {
            let that = this
            uni.navigateTo({
                url: '/pages/approval/veto?orderNumber=' + this.detailsData.orderNumber,
                success: function (res) {
                    let processName = '订单审批'
                    res.eventChannel.emit('emitDataHandle', { data: processName })
                }
            });
        },
        editHandle() {
            uni.redirectTo({
                url: '/pages/order/addOrder?type=edit&id=' + this.detailsData.id
            });
        },
        addRefund() {
			uni.navigateTo({
                url: '/pages/payment/addPayment'
            });
		},
        getColor(state) {
            let color;
            switch (state) {
                case '1001':
                color = 'rgba(103, 117, 133, 1)';
                break;
                case '1002':
                color = 'rgba(0, 186, 173, 1)';
                break;
                case '1003':
                color = 'rgba(255, 141, 26, 1)';
                break;
                case '1004':
                color = 'rgba(255, 141, 26, 1)';
                break;
                case '1005':
                color = 'rgba(255, 141, 26, 1)';
                break;
                case '1006':
                color = 'rgba(255, 0, 28, 1)';
                break;
                default:
                color = 'rgba(103, 117, 133, 1)';
            }
            return color;
        },
        openPopup() {
            this.$refs.popup.open()
        },
        select(item) {
            console.log(item)
            uni.showModal({
                title: '提示',
                content: '确定要执行此操作吗？',
                success: function (res) {
                    if (res.confirm) {
                        console.log('用户点击确定');
                    } else if (res.cancel) {
                        console.log('用户点击取消');
                    }
                }
            });
        },
        // 
        getStatus() {
            if(this.detailsData.orderStatus == '1003' || this.detailsData.orderStatus == '1004' || this.detailsData.orderStatus == '1005') {
                return true
            }
        },
        close() {
            this.show = false
        },
        backHandle() {
            uni.navigateBack()
        }
    }
}
</script>

<style lang="scss" scoped>
/deep/.uni-navbar__header-btns-right {
    width: 64px !important;
}

.orderApprovalDetails {
    padding-bottom: 150rpx;
}

.orderApprovalDetails-content {
    margin: 20rpx 0;

    .item {
        padding: 0 32rpx;
        flex: 1;
        margin-bottom: 32rpx;
        // 超出隐藏
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;

        >:nth-child(1) {
            font-size: 28rpx;
            font-weight: 400;
            color: rgba(103, 117, 133, 1);
            margin-bottom: 8rpx;
        }

        >:nth-child(2) {
            font-size: 30rpx;
            font-weight: 500;
            color: rgba(12, 16, 25, 1);
                   // 超出隐藏
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
        }
    }

    .customer-info {
        border-radius: 24rpx;
        background: rgba(255, 255, 255, 1);
        padding: 32rpx 0;
    }

    .item-title {
        padding: 48rpx 32rpx 20rpx 32rpx;
        font-size: 32rpx;
        font-weight: 500;
        color: rgba(12, 16, 25, 1);
    }

    .item-content {
        background: rgba(255, 255, 255, 1);
        padding: 0 32rpx;
        border-radius: 24rpx;

        .item-content-row {
            display: flex;
            justify-content: space-between;
            padding: 26rpx 0;
            font-size: 28rpx;
            border-bottom: 2rpx solid rgba(240, 240, 240, 1);

            >view:nth-child(1) {
                font-weight: 400;
                color: rgba(103, 117, 133, 1);
                width: 140rpx;
            }

            >view:nth-child(2) {
                flex: 1;
                font-weight: 500;
                color: rgba(12, 16, 25, 1);
                // 超出隐藏显示省略号
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
                text-align: right;
            }
        }
    }
}

.bottom-box {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-around;
    background: rgba(255, 255, 255, 1);
    box-shadow: 0px 0px 12rpx rgba(0, 0, 0, 0.1);
    > view {
        padding: 16rpx 0
    }

    .row-box {
        display: flex;
        align-items: center;
    }

    .column-box {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }

    text {
        font-size: 28rpx;
        font-weight: 500;
        color: rgba(12, 16, 25, 1);
        margin-left: 8rpx;
    }

}
</style>